package cn.net.xyan.pay.wechat

import cn.net.xyan.pay.wechat.service.WeChatMenuService
import cn.net.xyan.pay.wechat.service.WeChatVendorUserInfoProvider
import me.chanjar.weixin.mp.api.WxMpConfigStorage
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage
import me.chanjar.weixin.mp.api.WxMpService
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration

/**
 * Created by zarra on 2017/3/28.
 */


@Configuration
@ComponentScan
class WeChatConfiguration{

    companion object {

        val appID = "wx293406d1725c945e"
        val appSecret = "4b46d2dcfb35b111a3f41d5cc10b423d"
        val token = "xyan"
        val aesKey = "QJtRsrWtJi2sKomeDePN0WqAHOcMXVXylTVSRCdGToB"
    }

    @Bean
    fun wxMpConfigStorate():WxMpConfigStorage{
        val config = WxMpInMemoryConfigStorage()

        config.appId = appID
        config.secret = appSecret
        config.token = token
        config.aesKey = aesKey

        return config
    }

    @Autowired
    @Bean
    fun wxMpService(configStorage:WxMpConfigStorage): WxMpService {
        val service = WxMpServiceImpl()

        service.wxMpConfigStorage = configStorage

        return service
    }

    @Bean
    @Autowired
    fun weChatMenuService(wxMpService:WxMpService):WeChatMenuService{
        val menuService =  WeChatMenuService()
        menuService.wxMpService = wxMpService
        return menuService
    }

    @Bean
    fun weChatVendorUserInfoProvider(): WeChatVendorUserInfoProvider {
        val weChatVendorUserInfoProvider = WeChatVendorUserInfoProvider()
        return weChatVendorUserInfoProvider
    }
}